home *** CD-ROM | disk | FTP | other *** search
- # Skeleton Python source for embedding Python into ObjC programs.
- # This source file expects to be run by the ObjC code in PythonGlue.m
- # and it expects to live in Contents/Resources of some .app bundle.
- # It will add the Resources folder and its PyObjC subfolder to
- # sys.path and import any modules found in Resources (which in
- # turn makes any PyObjC classes in these modules available to the
- # ObjC runtime system).
- import os
- import sys
-
- DEBUG = 0
-
- def main():
- # First find the Resource folder of the current application
- resource_folder, ourname = os.path.split(__file__)
- if DEBUG:
- print "PythonGlue: resource folder:", resource_folder
-
- # IMPORTANT: 1. Make our Engine folder the first one; 2. Make the path to our own PyObjC
- # installation appear *before* the system-wide PyObjC, if exists.
- sys.path.insert(0, resource_folder)
- sys.path.insert(0, os.path.join(resource_folder, "lib/python2.3/site-packages/PyObjC"))
- sys.path.insert(0, os.path.join(resource_folder, "Engine"))
-
- # Now import all modules from the resource folder
- count = 0
- extension = '.py'
- extensionLen = len(extension)
- for filename in os.listdir(resource_folder):
- if filename[-extensionLen:] == extension and filename != ourname:
- module_name = filename[:-extensionLen]
- if DEBUG:
- print "PythonGlue: import", module_name
- __import__(filename[:-extensionLen])
- count = count + 1
- if count == 0:
- print "PythonGlue: Warning: no Python modules found"
-
- if __name__ == '__main__':
- main()
-